package event.numberevent;

/**rappresenta un numero che può essere ascoltato da varie classi.
 * 
 * @author koldar
 * @version 1.1
 *
 * @param <NUMBER>
 */
public class StateNumber<NUMBER extends Number> {

	private NUMBER value;
	private NumberManagerExtreme<NUMBER> list;
	
	public StateNumber(NUMBER initialvalue){
		this.value=initialvalue;
		this.list=new NumberManagerExtreme<NUMBER>();
	}
	
	public void addNumberListener(NumberListener<NUMBER> listener){
		this.list.add(listener);
	}
	public void removeNumberListener(NumberListener<NUMBER> listener){
		this.list.remove(listener);
	}

	/**
	 * @return the value
	 */
	public NUMBER getValue() {
		return value;
	}

	/**
	 * @param value the value to set
	 */
	public void setValue(NUMBER newvalue) {
		if (!this.value.equals(newvalue)){
			NUMBER oldvalue=this.value;
			this.value = newvalue;
			this.list.fireNumberEvents(new NumberEvent<NUMBER>(this,newvalue,oldvalue));
		}
	}
	
	
}
